<template>
  <div class="home">
    <el-container>
      <el-header>
        <div>
          <img src="https://ftp.bmp.ovh/imgs/2021/05/684c59686a76f389.jpg" alt />
          <span class="title">公司后台管理系统</span>
        </div>
        <el-button type="success" @click="logout" size="mini">退出登录</el-button>
      </el-header>
      <el-container>
        <el-aside class="elaside" :width="isOpen ? '200px' : '44px'">
          <div @click="switchMenu" class="toggleBtn">
            <i :class="isOpen?'el-icon-s-unfold':'el-icon-s-fold'"></i>
          </div>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            background-color="#545c64"
            text-color="#fff"
            active-text-color="#ffd04b"
            :unique-opened="true"
            :router="true"
          >
            <!-- 一级菜单 -->
            <el-submenu v-for="item in menulist" :key="item.id" :index="item.id + '' ">
              <template slot="title">
                <i :class="iconObj[item.name]"></i>
                <span>{{item.name}}</span>
              </template>
              <!-- 二级菜单 -->
              <el-menu-item v-for="subitem in item.child" :key="subitem.id" :index="subitem.path">
                <template slot="title">
                  <i :class="iconObj[subitem.name]"></i>
                  <span>{{subitem.name}}</span>
                </template>
              </el-menu-item>
            </el-submenu>
          </el-menu>
        </el-aside>

        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  props: [],
  components: {},
  data() {
    return {
      menulist: [],
      isOpen: true,
      iconObj: {
        用户管理: "iconfont iconyonghuguanli",
        员工管理: "iconfont iconyuangongguanli",
        商品管理: "iconfont iconshangpinguanli",
        订单管理: "iconfont icondingdanguanli35",
        数据统计: "iconfont iconshujutongji",
        用户列表: "iconfont iconyuangongliebiao",
        员工列表: "iconfont iconuser-list",
        商品列表: "iconfont iconshangpinliebiao",
        分类参数: "iconfont iconcanshu",
        商品分类: "iconfont iconshangpinfenlei"
      }
    };
  },
  //方法 函数写这里
  methods: {
    logout() {
      window.sessionStorage.clear();
      this.$router.push("/login");
    },
    switchMenu() {
      this.isOpen = !this.isOpen;
    },
    async getmenus() {
      const res = await this.$http.get("/api/menu");
      if (!res.status == "ok") return;
      this.menulist = res.data.data;
    }
  },
  //计算属性
  computed: {},
  //侦听器
  watch: {},
  //过滤器
  filters: {},
  //以下是生命周期
  //组件创建之前
  beforeCreate() {},
  //组件创建之后
  created() {
    this.getmenus();
  },
  //页面渲染之前
  beforeMount() {},
  //页面渲染之后
  mounted() {},
  //页面视图数据更新之前
  beforeUpdate() {},
  //页面视图数据更新之后
  updated() {},
  //页面销毁之前
  beforeDestroy() {},
  //页面销毁之后
  destroyed() {}
};
</script>


<style  lang="scss"  scoped >
.el-menu {
  border-right: none;
}

.title {
  color: white;
  font-size: 30px;
}
.el-container {
  height: 100vh;
}
.el-header {
  background-color: #0c212b;
  height: 80px !important;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.el-header div {
  display: flex;
  align-items: center;
}
.el-header img {
  width: 60px;
  height: 60px;
  padding-right: 6px;
  border-radius: 50%;
}
.el-aside {
  background-color: #4e72b8;
}
.el-main {
  background-color: #e9eef3;
}

.iconfont {
  margin-right: 10px;
}

.toggleBtn {
  line-height: 24px;
  color: #fff;
  text-align: left;
  font-size: 18px;
  padding-left: 12px;
  cursor: pointer;
  background-color: #009ad6;
}

.elaside {
  transition: all 0.5s ease;
}
</style>